home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ML_3DROT.ZIP / SOURCES / FIG5.PAS < prev    next >
Pascal/Delphi Source File  |  1996-12-26  |  3KB  |  134 lines

  1. {
  2.   Example of using the 3D "engine", by Maple Leaf, 1996
  3.  
  4.   This code is freeware. If you find it useful, feel free to do whatever
  5.   you want with it, with only one condiion: give some small greetings to
  6.   Maple Leaf in your productions that use parts of it.
  7.  
  8.                                                         Maple Leaf, '96
  9.  
  10.   btw, I'm too lazy to write down kilos of comments...   :-)
  11. }
  12. uses xmode,crt,engine3d;
  13.  
  14. var a,b:word;
  15.     pal:array[byte] of record r,g,b:byte end;
  16.     capag,cvpag : word;
  17.     dd:integer;
  18.     coord:array[0..730] of record x,y,z:integer end;
  19.     RealMapping : Boolean;
  20.     ch:char;
  21.     MaxPnt:word;
  22.     RotStep,TiltStep:longint;
  23.  
  24. Procedure GenFig;
  25. var angle:integer; hh:real; cnt:word;
  26. const rad = 40;
  27. begin
  28.   cnt:=0; angle:=0; hh:=0;
  29.   repeat
  30.     with coord[cnt] do begin
  31.       x:=Trunc(rad*cos(angle*pi/180));
  32.       y:=Trunc(rad*sin(angle*pi/180));
  33.       z:=Trunc(hh);
  34.     end;
  35.     hh:=hh+0.3;
  36.     inc(cnt);
  37.     inc(angle,4);
  38.   until cnt>127;
  39.   MaxPnt:=cnt
  40. end;
  41.  
  42. Procedure PuneFig;
  43. var i:integer; cnt:word;
  44. begin
  45.   cnt:=0;
  46.   {xvwait;}
  47.   xclrvpage(capag);
  48.   for i:=0 to MaxPnt-1 do begin
  49.     _3dx:=coord[i].x+100;
  50.     _3dy:=coord[i].y;
  51.     _3dz:=coord[i].z+10;
  52.     asm
  53.        cmp RealMapping,1
  54.        je @1
  55.        call IntMapCoordinates
  56.        jmp @2
  57.     @1:call MapCoordinates
  58.     @2:
  59.     end;
  60.     xvplot(_2dx,_2dy,(i+2) shl 3,capag);
  61.   end;
  62. end;
  63.  
  64. Procedure IntroText;
  65. begin
  66.   Writeln('3D Figure, by Maple Leaf, 1996.');
  67.   Writeln(#13#10,' Hot keys are:'#13#10);
  68.   Writeln('   <M>     - Change mapping method (float/integer)');
  69.   Writeln('   <Left>  - Decrement horizontal speed of rotation');
  70.   Writeln('   <Right> - Increment horizontal speed of rotation');
  71.   Writeln('   <Up>    - Increment vertical speed of rotation');
  72.   Writeln('   <Down>  - Decrement vertical speed of rotation');
  73.   Writeln(#13#10'Press a key to start ...');
  74.   Readkey;
  75. end;
  76.  
  77. begin
  78.   ClrScr;
  79.   GenFig;
  80.   IntroText;
  81.   xinitvideo(0);
  82.   xclrvram;
  83.   for a:=1 to 255 do with pal[a] do begin
  84.     r:=Trunc(63*a/255);
  85.     g:=Trunc(40);
  86.     b:=Trunc(63-63*a/255);
  87.   end;
  88.   xsetpalette(@pal);
  89.   ZoomFactor:=500;
  90.   Perspective:=True;
  91.   SetObserverPosition(0,0,500);
  92.   SetAngles(0,0);
  93.   capag:=0;
  94.   cvpag:=3;
  95.   dd:=10;
  96.   RealMapping:=false;
  97.   RotStep:=2;
  98.   TiltStep:=3;
  99.   repeat
  100.    repeat
  101.  
  102.     xvwait;
  103.     xsetvpage(cvpag);
  104.  
  105.     RotAngle:=RotAngle+RotStep;
  106.     TiltAngle:=TiltAngle+TiltStep;
  107.     if RotAngle>359 then RotAngle:=360-RotAngle;
  108.     if RotAngle<0 then RotAngle:=360+RotAngle;
  109.     if TiltAngle>359 then TiltAngle:=360-TiltAngle;
  110.     if TiltAngle<0 then TiltAngle:=360+TiltAngle;
  111.     {SetAngles(RotAngle,TiltAngle);}
  112.  
  113.     PuneFig;
  114.  
  115.     inc(capag); if capag>3 then capag:=0;
  116.     inc(cvpag); if cvpag>3 then cvpag:=0;
  117.  
  118.    until keypressed;
  119.    ch:=readkey;
  120.    case UpCase(ch) of
  121.      'M': { Mapping mode } RealMapping:=not RealMapping;
  122.      #0: begin
  123.        ch:=readkey;
  124.        case ch of
  125.          #72: {Up}    inc(RotStep);
  126.          #80: {Down}  dec(RotStep);
  127.          #75: {Left}  dec(TiltStep);
  128.          #77: {Right} inc(TiltStep);
  129.        end;
  130.      end;
  131.    end;
  132.   until ch=#27;
  133.   textmode(25);
  134. end.